var t = require("../../@babel/runtime/helpers/defineProperty"), a = function(t) {
    e && console.log(t);
}, e = !1, i = null, o = 0, h = 0, n = 0, s = 0, c = 0, g = 0, x = 0, l = 0, d = 1, f = 0, r = 0, b = .15, u = .15, v = .6, p = .6, m = 0, H = 0, W = 0, T = 0, R = 0, w = 0;

Component({
    data: {
        imagePath: "",
        stageLeft: 0,
        stageTop: 0,
        stageWidth: 0,
        stageHeight: 0,
        boxWidth: 0,
        boxHeight: 0,
        boxLeft: 0,
        boxTop: 0,
        canvasWidth: 0,
        canvasHeight: 0
    },
    methods: {
        fnInit: function(m) {
            var H = this, W = m.imagePath;
            m.debug && (e = m.debug), m.minBoxWidthRatio && (b = m.minBoxWidthRatio), m.minBoxHeightRatio && (u = m.minBoxHeightRatio), 
            m.initialBoxWidthRatio && (v = m.initialBoxWidthRatio), m.initialBoxHeightRatio && (p = m.initialBoxHeightRatio), 
            m.aspectRatio && (i = m.aspectRatio), wx.createSelectorQuery().in(this).select(".layout").boundingClientRect(function(e) {
                a(e), e.left, e.top, o = e.width, h = e.height, wx.getImageInfo({
                    src: W,
                    success: function(e) {
                        a(e), x = e.width, l = e.height;
                        var m = x / l;
                        m >= o / h ? d = l / (g = (c = o) / m) : (g = h, d = x / (c = h * m)), n = (o - c) / 2, 
                        s = (h - g) / 2, f = c * b, r = g * u;
                        var T = c * v, R = g * p;
                        i && (R = T / i), R > g && (T = (R = g) * i);
                        var w = (c - T) / 2, L = (g - R) / 2;
                        H.setData(t(t(t(t(t({
                            imagePath: W,
                            canvasWidth: 1 * x,
                            canvasHeight: 1 * l,
                            stageLeft: n,
                            stageTop: s,
                            stageWidth: c,
                            stageHeight: g
                        }, "stageHeight", g), "boxWidth", T), "boxHeight", R), "boxLeft", w), "boxTop", L));
                    }
                });
            }).exec();
        },
        fnTouchStart: function(t) {
            a("start"), a(t);
            var e = t.touches[0], i = e.pageX, o = e.pageY;
            R = i, w = o, m = this.data.boxLeft, H = this.data.boxTop, W = this.data.boxWidth, 
            T = this.data.boxHeight;
        },
        fnTouchMove: function(t) {
            a("move"), a(t);
            var e = t.target.id, o = t.touches[0], h = o.pageX, n = o.pageY, s = h - R, x = n - w;
            if ("box" == e) {
                var l = m + s, d = H + x;
                l < 0 && (l = 0), d < 0 && (d = 0), l + W > c && (l = c - W), d + T > g && (d = g - T), 
                this.setData({
                    boxLeft: l,
                    boxTop: d
                });
            } else if ("lt" == e) {
                i && (x = s / i);
                var b = m + s, u = H + x;
                b < 0 && (b = 0), u < 0 && (u = 0), m + W - b < f && (b = m + W - f), H + T - u < r && (u = H + T - r);
                var v = W - (b - m), p = T - (u - H);
                0 == u && i && 0 != b && (b = W - (v = p * i) + m), 0 == b && i && (u = T - (p = v / i) + H), 
                v == f && i && (u = T - (p = v / i) + H), this.setData({
                    boxTop: u,
                    boxLeft: b,
                    boxWidth: v,
                    boxHeight: p
                });
            } else if ("rt" == e) {
                i && (x = -s / i);
                var L = W + s;
                L < f && (L = f), m + L > c && (L = c - m);
                var B = H + x;
                B < 0 && (B = 0), H + T - B < r && (B = H + T - r);
                var M = T - (B - H);
                0 == B && i && L != c - m && (L = M * i), L == c - m && i && (B = T - (M = L / i) + H), 
                L == f && i && (B = T - (M = L / i) + H), this.setData({
                    boxTop: B,
                    boxHeight: M,
                    boxWidth: L
                });
            } else if ("lb" == e) {
                i && (x = -s / i);
                var y = m + s;
                y < 0 && (y = 0), m + W - y < f && (y = m + W - f);
                var C = W - (y - m), D = T + x;
                D < r && (D = r), H + D > g && (D = g - H), D == g - H && i && 0 != y && (y = W - (C = D * i) + m), 
                0 == y && i && (D = C / i), C == f && i && (D = C / i), this.setData({
                    boxLeft: y,
                    boxWidth: C,
                    boxHeight: D
                });
            } else if ("rb" == e) {
                i && (x = s / i);
                var P = W + s;
                P < f && (P = f), m + P > c && (P = c - m);
                var I = T + x;
                I < r && (I = r), H + I > g && (I = g - H), I == g - H && i && P != c - m && (P = I * i), 
                P == c - m && i && (I = P / i), P == f && i && (I = P / i), this.setData({
                    boxWidth: P,
                    boxHeight: I
                });
            }
        },
        fnTouchEnd: function(t) {
            a("end");
        },
        fnTouchCancel: function(t) {
            a("cancel");
        },
        fnCrop: function(t) {
            var a = this, e = function() {}, i = function() {}, o = function() {};
            null != t.success && (e = t.success), null != t.fail && (i = t.fail), null != t.complete && (o = t.complete);
            var h = a.data.imagePath, n = wx.createCanvasContext("canvas", a), s = a.data.boxLeft, c = a.data.boxTop, g = a.data.boxWidth, x = a.data.boxHeight, l = Math.ceil(s * d), f = Math.ceil(c * d), r = Math.ceil(g * d), b = Math.ceil(x * d), u = Math.ceil(1 * r), v = Math.ceil(1 * b);
            n.drawImage(h, l, f, r, b, 0, 0, u, v), n.draw(!1, function() {
                wx.canvasToTempFilePath({
                    x: 0,
                    y: 0,
                    width: u,
                    height: v,
                    destWidth: r,
                    destHeight: b,
                    canvasId: "canvas",
                    fileType: "jpg",
                    quality: 1,
                    success: e,
                    fail: i,
                    complete: o
                }, a);
            });
        }
    }
});